#include<bits/stdc++.h>
using namespace std;
int n;
int t;
int a[200005];
int maxn;
void find1(int s,int ans,int k){
    maxn=max(maxn,ans);
    if(s<=0) return;
    if(a[s]==a[s+1]) find1(s-1,ans+a[s],k);
    else{
        find1(s-1,ans,k);
    }
    if(a[s]==a[k]) find1(s-1,ans+a[s],s+1);
    else find1(s-1,ans,s+1);
}

int main(){
    freopen("color2.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        maxn=0;
        cin>>n;
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        find1(n-1,0,n);
        cout<<maxn<<endl;
    }
    return 0;
}
